#ifndef _OVP_H_
#define _OVP_H_

#define OVP0  &_ovp0c0
#define OVP1  &_ovp1c0
#define OVP2  &_ovp2c0
#define OVP3  &_ovp3c0
#define OVP4  &_ovp4c0
#define OVP5  &_ovp5c0
#define OVP6  &_ovp6c0
#define OVP7  &_ovp7c0
#define OVP8  &_ovp8c0


#define OVP0DA 	0
#define OVP1DA  5
#define OVP2DA  90//119
#define OVP3DA  11
#define OVP4DA  90//100
#define OVP5DA  110
#define OVP6DA  85//

#define OVP7DA  30//100

#define OVP8DA  10


#define NO_Debounce			0
#define Debounce_2tsys		1
#define Debounce_4tsys		2
#define Debounce_8tsys		3
#define Debounce_16tsys		4
#define Debounce_32tsys		5
#define Debounce_64tsys		6
#define Debounce_128tsys	7

#define Hysteresis_0mV		0
#define Hysteresis_30mV		4
#define Hysteresis_60mV		8
#define Hysteresis_80mV		12

#define OVP_out_NonInvert	0
#define OVP_out_Invert		64

#define OVP0_N_DAC_IN		1
#define OVP0_N_IN			0

#define OVP1_N_DAC_IN		1
#define OVP1_N_IN			0

#define OVP6_P_IN0	0
#define OVP6_P_IN1	1

#define OVP7_P_IN0	0
#define OVP7_P_IN1	1



#define OVP_En		1
#define OVP_Dis		0

//#define		OVP3_ISR_ON()	{_ovp3f=0;_ovp3e=1;}
//#define		OVP3_ISR_OFF()	{_ovp3e=0;_ovp3f=0;}
//
//#define		OVP4_ISR_ON()	{_ovp4f=0;_ovp4e=1;}
//#define		OVP4_ISR_OFF()	{_ovp4e=0;_ovp4f=0;}
//
//#define		OVP5_ISR_ON()	{_ovp5f=0;_ovp5e=1;}
//#define		OVP5_ISR_OFF()	{_ovp5e=0;_ovp5f=0;}
#define		OVP6_ISR_ON()	{_ovp6f=0;_ovp6e=1;}
#define		OVP6_ISR_OFF()	{_ovp36=0;_ovp6f=0;}

#define		OVP7_ISR_ON()	{_ovp7f=0;_ovp7e=1;}
#define		OVP7_ISR_OFF()	{_ovp7e=0;_ovp7f=0;}

#define		OVP8_ISR_ON()	{_ovp8f=0;_ovp8e=1;}
#define		OVP8_ISR_OFF()	{_ovp8e=0;_ovp8f=0;}

#define	 NON_INVERTING_AMP		0
#define	 INVERTING_AMP			1
#define  EXTERN_AMP				2
#define	 DISABLE_RATIO_DOUBLE	0	//
#define	 ENABLE_RATIO_DOUBLE	1	//


typedef enum
{
	R2_R1_Ratio2	=	(unsigned char) 0x00,	/**< R2/R1=2  */
	R2_R1_Ratio5	=	(unsigned char) 0x01,	/**< R2/R1=5  */
	R2_R1_Ratio6	=	(unsigned char) 0x02,	/**< R2/R1=6  */
	R2_R1_Ratio7	=	(unsigned char) 0x03,	/**< R2/R1=7  */
	R2_R1_Ratio20	=	(unsigned char) 0x04,	/**< R2/R1=20 */
	R2_R1_Ratio25	=	(unsigned char) 0x05,	/**< R2/R1=25 */
	R2_R1_Ratio30	=	(unsigned char) 0x06,	/**< R2/R1=30 */
	R2_R1_Ratio35	=	(unsigned char) 0x07,	/**< R2/R1=35 */
}R2_R1_Ratio_TypeDef;

unsigned char OVP_Calibration(volatile unsigned char *OVP_n,unsigned char DAC_Vaule);
void OVP0_Init(unsigned char temp_Calibration_Value0,unsigned char DA_Value);
void OVP1_Init(unsigned char temp_Calibration_Value1,unsigned char DA_Value);
void OVP2_Init(unsigned char temp_Calibration_Value2,unsigned char DA_Value);
void OVP3_Init(unsigned char temp_Calibration_Value3,unsigned char DA_Value);
void OVP4_Init(unsigned char temp_Calibration_Value4,unsigned char DA_Value);
void OVP5_Init(unsigned char temp_Calibration_Value5,unsigned char DA_Value);
void OVP6_Init(unsigned char temp_Calibration_Value6,unsigned char DA_Value);
void OVP7_Init(unsigned char temp_Calibration_Value6,unsigned char DA_Value);

void OVP_SW(volatile unsigned char *OVP_n,unsigned char  SW_Status);
void OVP_02345_Init(volatile unsigned char *OVP_n,unsigned char DAC_Vaule,unsigned char debounce_time,unsigned char Hysteresis_voltage,unsigned char debounce_out_polarity,unsigned char Calibration_value);
void OVP_0_Init(unsigned char  OVP_N_Sel,unsigned char DAC_Vaule,unsigned char debounce_time,unsigned char Hysteresis_voltage,unsigned char debounce_out_polarity,unsigned char Calibration_value);
void OVP_1_Init(unsigned char  OVP_N_Sel,unsigned char DAC_Vaule,unsigned char debounce_time,unsigned char Hysteresis_voltage,unsigned char debounce_out_polarity,unsigned char Calibration_value);
void OVP_6_Init(unsigned char  OVP_P_Sel,unsigned char DAC_Vaule,unsigned char debounce_time,unsigned char Hysteresis_voltage,unsigned char debounce_out_polarity,unsigned char Calibration_value);
void OVP_7_Init(unsigned char  OVP_P_Sel,unsigned char DAC_Vaule,unsigned char debounce_time,unsigned char Hysteresis_voltage,unsigned char debounce_out_polarity,unsigned char Calibration_value);

unsigned char OPA_Calibration(void);
void OPA_Init(unsigned char  Phase, unsigned char  RatioDouble, unsigned char R2_than_R1, unsigned char temp_Calibration_Value);
void OPAInit();

extern	volatile unsigned char	OVP2_TimeCnt,OVP2_Cnt,OVP2_ClrFlag;

#endif

/******************* End of file ***************/